package com.plant.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.plant.dao.BaseDao;
import com.plant.entity.PgcWiki;
import com.plant.service.WikiService;

/**
 *
 * @author 植物先生-李琦
 * 
 * 			---下面是注册接口
 */
@Service  //依赖注册 必须写注册 下面在写resource资源
@Transactional
public class WikiServiceImpl implements WikiService{
    @Resource(name = "baseDaoImpl")//注解扫描basedao接口方法
    private BaseDao baseDao;

	public boolean addwiki(PgcWiki wiki) {	//新建百科分类
		boolean isadd=true; 
		isadd=baseDao.add(wiki);
		return isadd;
	}
	public boolean upwiki(PgcWiki wiki) {	//修改百科分类
		boolean isadd=true; 
		isadd=baseDao.update(wiki);
		return isadd;
	}
	public boolean delwiki(PgcWiki wiki) {	//删除百科分类
		boolean isadd=true; 
		isadd=baseDao.del(wiki);
		return isadd;
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> listwiki(Integer page,String time,PgcWiki wiki) {//显示百科分类列表
		List<Object> list3=new ArrayList<Object>();
    	String hql="select a.id,a.title,a.create_time from pgc_wiki as a where user_id=("+wiki.getUserId()+") and create_time<? order by create_time desc";//--通过 时间分页查询 显示10条
    	list3=baseDao.findfenye((page-1)*20, 20, hql, time,null);
        return list3;
	}
	
	
	public List<Object> onewike(PgcWiki wiki) {//--显示某一篇百科详情 用于修改
		String hql="from PgcWiki where id=?";
		return baseDao.find(hql, wiki.getId());
	}
	
	
	public Long wikicount(PgcWiki wiki) {//---统计马甲用户创建百科的条数
		String hql="select count(id) from PgcWiki where userId=("+wiki.getUserId()+")";
		Long lo=baseDao.CountHql(hql);
		System.out.println("统计百科条数"+lo);
		return lo;
	}
	
	
	public Object oneinf(PgcWiki wiki) {//------返回单个实体
		return baseDao.find(PgcWiki.class,wiki.getId());
	}
	
	
 }
